package com.app.controller;


import com.app.mapper.EnterpriseAlbumMapper;
import com.app.model.UserModel;
import com.app.service.UserService;
import com.app.util.Result;
import com.app.util.TokenUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@Controller
@RestController
@NoArgsConstructor
@AllArgsConstructor
@Data
public class EnterpriseAlbumController {

    @Autowired
    EnterpriseAlbumMapper enterpriseAlbumMapper;

    @Autowired
    UserService userService;
    //根据ID删除图集
    @GetMapping("/delAlbum")
    public Result<Object> delAlbum(int id,HttpServletRequest request){

        JSONObject json = new JSONObject();
        String token = request.getHeader("token");
        String mobile = TokenUtils.nothingness(token);
        if (mobile == null) {
            return Result.error(405,"token不存在");
        }

        UserModel user = userService.getUserByMobile(mobile);
        if(user==null)
        {
            return Result.error(405,"用户不存在");
        }
        enterpriseAlbumMapper.deleteById(id);
        return Result.success(null);
    }

}